package com.sinvo.oa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinvo.oa.entity.model.system.SysLoginLog;
import com.sinvo.oa.entity.model.system.SysOperLog;
import com.sinvo.oa.entity.vo.system.SysOperLogQueryVo;
import com.sinvo.oa.mapper.SysOperLogMapper;
import com.sinvo.oa.service.SysOperLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @Description SysOperLogService实现类
 */
@Service
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements SysOperLogService {

    @Override
    public void recordOperLog(SysOperLog sysOperLog) {
        this.save(sysOperLog);
    }

    @Override
    public Page<SysOperLog> findOperLogByPage(Page<SysOperLog> page, SysOperLogQueryVo sysOperLogQueryVo) {
        //操作模块
        String title = sysOperLogQueryVo.getTitle();
        //操作人
        String operator = sysOperLogQueryVo.getOperator();
        String createTimeBegin = sysOperLogQueryVo.getCreateTimeBegin();
        String createTimeEnd = sysOperLogQueryVo.getCreateTimeEnd();
        //封装条件
        LambdaQueryWrapper<SysOperLog> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(title)){
            queryWrapper.like(SysOperLog::getTitle,title);
        }
        if (!StringUtils.isEmpty(operator)){
            queryWrapper.like(SysOperLog::getOperName,operator);
        }
        //时间范围
        if (!StringUtils.isEmpty(createTimeBegin)) {
            queryWrapper.ge(SysOperLog::getCreateTime, createTimeBegin);
        }
        if (!StringUtils.isEmpty(createTimeEnd)) {
            queryWrapper.lt(SysOperLog::getCreateTime, createTimeEnd);
        }
        queryWrapper.orderByDesc(SysOperLog::getCreateTime);
        Page<SysOperLog> pageModel = this.page(page, queryWrapper);
        return pageModel;

    }
}
